load 'mars_voyages.rb'

mv = MarsVoyages.new

if ARGV[0] != nil
  if File.exist?(ARGV[0])  
    i = 1
    File.read(ARGV[0]).each_line do |line|
      if line.length > 1
        begin 
          mv.instance_eval(line, ARGV[0])
        rescue MarsException => e
          puts "Error occured on line " + i.to_s + ": " + e.to_s
          puts
        rescue SystemExit
          puts "Quit"
        end
      end
      i = i + 1
    end
  else
    puts ARGV[0] + " is not a file"
  end
else
  puts "Welcome to the mars voyages cli version 1.337!"
  puts "Just enter your commands to get going"
  while true 
    begin
      print ">" 
      STDOUT.flush
      sexylady = gets
      mv.instance_eval(sexylady.strip)
    rescue SystemExit
      puts "Goodbye dear stranger!"
      raise
    rescue MarsException => me
      puts me.to_s
      puts
    rescue Exception => e
      puts "Error occured: " + e.to_s
      puts
     end
  end
end